//
// Created by dq550457 on 19-1-8.
//

#ifndef WIFIDEMO_PROTOCOL_H
#define WIFIDEMO_PROTOCOL_H


#include <cstdint>
#include <jni.h>


typedef struct _netConf_ {
    uint8_t ssid_len;
    uint8_t ssid[32];
    uint8_t pwd_len;
    uint8_t pwd[64];
    uint16_t encrypMode;
} netConf;

typedef struct _deviceState_ {
    uint8_t state;
    uint8_t addr;
} deviceState;

enum {
    DEVICE_STATE = 0x11,

    REFRSH = 0x21,
    CONFIGN_NETWORK,
};

enum {
    SSID_TOKEN = 0xf1,
    PASSWORD_TOKEN,
    Encryp_TOKEN,
};

class protocol {
private:
    JNIEnv *env;
    int state;//1----remote,2-----air
protected:
    virtual bool processRefresh(const void *inbuf, uint8_t len);
    virtual bool processConfigNetwork(const void *inbuf, uint8_t len);
    virtual bool processDeviceState(const void *inbuf, uint8_t len);
public:
    protocol(JNIEnv *env) {
        this->env = env;
    }

    void setEnv(JNIEnv *env) {
        this->env = env;
    }

    virtual uint8_t refreshCommand(char * out);
    virtual uint8_t configNetworkCommand(const netConf * conf, char * out);
    virtual uint8_t deviceStateCommand(deviceState * state, char *out);
    virtual uint8_t process(const void *inbuf, uint8_t len);

    virtual void setState(int state) {
        this->state = state;
    }
};


#endif //WIFIDEMO_PROTOCOL_H
